const MyPromise = require('./MyPromise.js');

// let promise = new MyPromise((resolve, reject) => {
//   setTimeout(() => {
//     resolve('aaaaaa');
//   }, 100)
// });

// let p1 = promise.then(v => {
//   console.log(v);
//   return p1;
// })

// p1.then(v => {
//   console.log(v)
//   return 'dfghjkhfgdjk'
// }, err => {
//   console.log(err.message)
// }).then(v => {
//   console.log(v)
// })

function p3 () {
  return new MyPromise((resolve, reject) => {
    resolve('dsfsdf');
    // reject('11111')
  });
}

function p1 () {
  setTimeout(() => {
    console.log("p1")
  }, 2000)
}

// p3().finally(() => {
//   console.log("fffffff");
//   return p1();
// })
// .then(v => console.log(v)).catch(r => console.log(r))


var a = 10;
var obj = {
  a: 20,
  fn() {
    setTimeout(() => {
      console.log(this.a)
    })
  }
}
obj.fn()

// MyPromise.resolve(1).then(v => console.log(v))